/*
 * @Author: ChunLai
 * @Date: 2023-02-22 08:52:08
 * @LastEditTime: 2023-08-09 14:20:25
 * @Description: 全局对话框配置
 * @FilePath: \0.newInsure\src\utils\globalui.js
 */
import Vue from 'vue';
import { Dialog } from 'vant';
import router from '@/router';
// import { getDataFromUrl } from '@/utils/index';

/**
 * 全局Alert 替换ok
 * @param {*} content
 * @param {*} callback
 * @param {*} btnText
 * @param {*} title
 * 使用: this.$baseAlert('测试', ()=>{console.log("回调函数")});
 * this.$baseAlert(data.msg)
 * this.$baseAlert(``)
 * this.$baseAlert()
 */
Vue.prototype.$baseAlert = (content, callback, btnText) => {
  // console.log('baseAlert');
  Dialog.alert({
    title: '温馨提示',
    message: content,
    messageAlign: 'left',
    confirmButtonColor: '#DA251E',
    confirmButtonText: btnText || '确认',
    getContainer: 'body',
  }).then(() => {
    if (callback) {
      callback();
    }
  });
};

/**
 * 全局Confirm
 * @param {*} content
 * @param {*} callback1
 * @param {*} callback2
 * @param {*} title
 * @param {*} btnSureText
 * @param {*} btnCancelText
 * 使用: this.$baseConfirm('测试', ()=>{console.log("确定回调函数")},()=>{console.log("取消回调函数")})
 */
Vue.prototype.$baseConfirm = (
  content,
  callback1,
  callback2,
  btnSureText = '',
  btnCancelText = '',
  target = 'body'
) => {
  Dialog.confirm({
    title: '温馨提示',
    message: content,
    messageAlign: 'left',
    confirmButtonColor: '#DA251E',
    confirmButtonText: btnSureText || '确定',
    cancelButtonColor: '#666666',
    cancelButtonText: btnCancelText || '取消',
    getContainer: target,
  })
    .then(() => {
      if (callback1) {
        callback1();
      }
    })
    .catch(() => {
      if (callback2) {
        callback2();
      }
    });
};

// 已核保,禁止修改信息跳转
Vue.prototype.$forbidChangeOrder = () => {
  Dialog.confirm({
    title: '温馨提示',
    message: '该保单已存在,不可修改信息',
    confirmButtonColor: '#DA251E',
    getContainer: 'body',
  })
    .then(() => {
      router.replace('/billsure');
    })
    .catch(() => {});
};

// $backRouter() 替换ok
Vue.prototype.$backRouter = () => {
  router.go(-1);
};

// 暂不用
// Vue.prototype.$nextUpRouter = (curStep) => {
//   // console.log('nextUpRouter', curStep);
//   let cache = JSON.parse(vuex || '{}'),
//     lyObj = cache.page || {},
//     routerList = lyObj.routerList || [];
//   if (routerList.length === 0) return;
//   let index = routerList.indexOf(curStep),
//     routeName = routerList[index + 1];
//   router.push({
//     name: `${routeName}`,
//   });
// };
